#include <stdio.h>
#include <getopt.h>
#include "sockets.h"
#include "threads.h"
#include "string_functions.h"

void printHelp(char *filename);

int main(int argc, char *argv[]) {
	extern char *optarg;
	int opt;
	int port = 1300;

	while((opt = getopt(argc, argv, "hp:")) != -1) {
		switch(opt) {
		case 'h':
			printHelp(argv[0]);
			exit(0);
			break;
		case 'p':
			port = atoi(optarg);
			break;
		}
	}
	startup(port);
	
	/*
	char test[100], test2[100];
	int i;
	
	strcpy(test, "Dit is een test.");

	for(i=0; i<4; i++) {
		get_part(test, test2, i);
		printf("Part %i of '%s' = '%s'.\n", i, test, test2);
	}
	*/
	

	mainloop();

}

void printHelp(char *filename) {
	printf("Usage:\n\
  %s [options]\n\
Options:\n\
  -p port:  specify the port for listening (default: 1300)\n", filename);
}
